using System;
using System.Xml;
using System.Collections;


namespace ScenarioFramework.Modules.FormHelper
{
	//*********************************************************************
	//
	// XMLActions Class
	//
	// The XMLActions class represents a collection base of XMLAction
	// Its imports methods from bOSdotNET.XML.Data.XMLObjectSet like get set and add
	// 
	//
	//*********************************************************************

	public class XMLActions : bOSdotNET.XML.Data.XMLObjectSet
	{
		public const string MAIN_NODE	= "Actions";

		public const string NAME_ATTRIBUTE = "Name";

		/** FIELDS **/

		public string sName;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Empty **/
		public XMLActions()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width XML parsering**/
		public XMLActions(System.Xml.XmlNode nodeList)
		{
			this.Parse (nodeList);
		}

		/** Properties **/

		public string Name 
		{
			get { return sName; }
			set { sName = value; }
		}


		/** INSTANCE METHODS **/

		override public void Init()
		{
			sName = string.Empty;

			this.RemoveAll();
		}

		override public void Parse(System.Xml.XmlNode nodeList)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<nodeList.Attributes.Count;i++)
			{
				node = nodeList.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLActions.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;
				}
			}

			/** find subcollection fileds to add in XMLActions **/
			for ( int i=0; i<nodeList.ChildNodes.Count;i++)
			{
				node = nodeList.ChildNodes[i];

				switch ( node.Name) 
				{
					case XMLAction.MAIN_NODE:
						this.Add ( new XMLAction(node));
						break;
				}
			}

		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode XMLNode = new bOSdotNET.XML.XMLNode(XMLActions.MAIN_NODE);
			XMLNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLActions.NAME_ATTRIBUTE, sName) );

			for ( int i=0; i<this.Count;i++)
			{
				XMLNode.AddNode ( this[i].GetXMLNode() );
			}

			return XMLNode;
		}


		/** Method for return an action from collection **/
		public XMLAction Get(string sName)
		{
			XMLAction action;

			for ( int i=0; i<this.List.Count; i++)
			{
				action = (XMLAction)this.List[i];
				if ( action.sName == sName )
				{
					return action;
				}
			}

			throw new Exception.XMLActionNotFound();
		}

		/** Method for checking an ation in collection **/
		public bool AlmostIn(XMLActions vValues)
		{
			XMLAction leftAction;
			XMLAction rightAction;

			for ( int i=0; i<this.List.Count; i++)
			{
				leftAction = (XMLAction)this.List[i];

				try
				{
					rightAction = vValues.Get(leftAction.sName);
				}
				catch (Exception.XMLActionNotFound)
				{
					return false;
				}
			}
			
			return true;
		}

		/** Method for checking an action in collection **/
		public bool AlmostInByName (string sName)
		{
			XMLAction Action;

			for ( int i=0; i<this.List.Count; i++)
			{
				Action = (XMLAction)this.List[i];

				if (Action.sName == sName)
				{
					return true;
				}
			}
			
			return false;
		}

	

	}
}
